import pygame, sys
from pygame.locals import *
from data import *
import game

def cutscene(screen, text, gameCheck = None):
    font = pygame.font.Font(filepath("fonts/font1.ttf"), 32)
    black = pygame.Surface((800, 480))
    black.fill((0, 0, 0))
    keepGoing = True
        

    while keepGoing:
        for e in pygame.event.get():
            if e.type == QUIT:
                sys.exit()
            if e.type == KEYDOWN:
                if e.key == K_ESCAPE:
                    if gameCheck == None:
                        keepGoing = False
                    else:
                        gameCheck.keepGoing = False
                if e.key == K_RETURN:
                    if gameCheck == None:
                        game.Game(screen)
                        keepGoing = False
                    else:
                        keepGoing = False
                           
        screen.fill((0, 0, 0))
        
        y = 1
        for line in text:
            ren = font.render(line, 1, (255, 255, 255))
            screen.blit(ren, (400-ren.get_width()/2, y*(font.get_height()+3)))
            y += 1
        
        ren = font.render("Press Enter to continue", 1, (255, 255, 255))
        screen.blit(ren, (400 - ren.get_width()/2, 400))
        
        pygame.display.flip()
